import axios from 'axios';

const service = axios.create({
  baseURL: 'http://127.0.0.1:8080',
  timeout: 60 * 1000,
});

service.interceptors.request.use(
  config => {
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

service.interceptors.response.use(
  async response => {
    let res = response.data;
    return res;
  },
  error => {
    return Promise.reject(error);
  }
);

const callApi = (url, method = 'get', data) => {
  return service({
    url,
    method,
    params: method === 'get' ? data : {},
    data: method === 'post' ? data : {},
  });
};

export const getApi = (url, data) => callApi(url, 'get', data);

export const postApi = (url, data) => callApi(url, 'post', data);
